import {
    // BrowserRouter as Router,
    Route,
    Redirect,
    Switch
} from 'react-router-dom'
import {Suspense} from 'react'

let RouterView=(props)=>{
    let {RouterList}=props
    let routerList=RouterList.filter((item,index)=>{
        return !item.to
    })
    let redirect=RouterList.filter((item,index)=>{
        return item.to
    })[0]
    return (
        <Suspense fallback={<div>...loading</div>}>
                <Switch>
                    {
                        routerList&&routerList.length?routerList.map((item,index)=>{
                            return <Route path={item.path} key={index} render={(routerProps)=>{
                                window.routerProps = routerProps
                                return <item.component {...routerProps} child={item.children}></item.component>
                            }}>

                            </Route>
                        }):''
                    }
                    {
                        redirect?<Redirect from={redirect.from} to={redirect.to}></Redirect>:''
                    }
                </Switch>
        </Suspense>
    )
}

export default RouterView